<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use App\Admin\Extensions\Traits\ModelTree;
use Illuminate\Database\Eloquent\Factories\HasFactory;

class BlindBoxOrder extends Model
{
    use HasFactory;
    use ModelTree;
    
    protected $guarded = ['id'];

    public function scopePaid(Builder $builder): Builder
    {
        return $builder->whereNotNull('paid_at');
    }

    public function isPaid(): bool
    {
        return (bool)$this->paid_at;
    }

    public function product()
    {
        return $this->belongsTo(Product::class);
    }

    public function level()
    {
        return $this->belongsTo(BlindBoxLevel::class,'blind_box_level_id','id');
    }


     public function user()
    {
        return $this->belongsTo(User::class);
    }

    public function order()
    {
        return $this->hasOne(Order::class,'blind_box_order_id','id');
    }
}
